<template>
	<view>
		<view class="header" :style="'padding-top: '+bartop+'px; background:none; padding-bottom:10rpx'">
			<view class="goodsmsgheader headertop" style="width: 100%;">
				<navigator open-type="navigateBack" style="padding:10rpx">
					<image src="https://x.bilinmeiju.com/static/myfangchan/zjt.png" mode="aspectFit"></image>
				</navigator>
				<text>访客通行码</text>
				<!-- <image src="/static/goodsmsghei.png" mode="aspectFit" bindtap="showmsg" wx:if="{{cartlen=='00'?false:true}}"><text>{{cartlen}}</text></image> -->
			</view>
		</view>
		<view class="box topnext">
			<view class="box1" style="padding-top: 50px;">
				<image class="box1img" :src="info.user.headimgurl" style="border-radius: 50%;" mode=""></image>
				<view class="box2">
					<view class="box2text">乾多多</view>
					<view class="box22text1">快告诉小伙伴我在用「比邻美居」</view>
				</view>
			</view>

			<view class="box-2">
				<view class="box2-1">
					房间号
				</view>
				<view class="box2-2">
					<view class="box2-2textx">
						{{info.room}}
					</view>
					<!-- <image class="box2-2img" src="https://x.bilinmeiju.com/static/myfangchan/fuzhi.png" mode=""></image> -->
				</view>
			</view>
			<view class="box-2">
				<view class="box2-1">
					有效期至
				</view>
				<view class="box2-2">
					<view class="box2-2textx">
						{{info.etime}}
					</view>
					<image class="box2-2img" src="https://x.bilinmeiju.com/static/myfangchan/fuzhi.png" mode=""></image>
				</view>
			</view>

			<image class="beijing2" :src="path" mode=""></image>

			<view class="text">请勿随便把二维码给别人</view>

			<view class="end">
				<view class="end1" @click="saveImage(path)">
					<image class="end1img" src="https://x.bilinmeiju.com/static/myfangchan/baocun.png" mode=""></image>
					<view class="end1text">
						保存
					</view>
				</view>
				<view class="end1">
					<image class="end1img" src="https://x.bilinmeiju.com/static/myfangchan/weixin.png" mode=""></image>
					<view class="end1text">
						微信
					</view>
				</view>
				<!-- <view class="end1">
					<image class="end1img" src="https://x.bilinmeiju.com/static/myfangchan/pyq.png" mode=""></image>
					<view class="end1text">
						朋友圈
					</view>
				</view> -->
			</view>
		</view>
		<image src="https://x.bilinmeiju.com/static/myfangchan/beijing1.png" class="beijing1" mode=""></image>
		<image src="https://x.bilinmeiju.com/static/myfangchan/beijing.png" class="beijing" mode=""></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				CustomBar: 0,
				topheight: 0,
				roomId: 0,
				shenfen: 2,
				name: '',
				headimgurl: '',
				code: '',
				endtime: '',
				path: '',
				bartop: 0,
				info: {},
				id: ''
			}
		},
		onLoad(options) {
			this.id = options.id
			this.roomId = options.roomid;
			this.shenfen = options.shenfen;
			this.bartop = this.$bartop
			// this.getqrcode();
			this.getinfo()
		},
		// onShareAppMessage(res) {
		// 	return {
		// 		title: '房产二维码绑定',
		// 		path: '/pages/index/home?scene=q_' + this.code,
		// 		imageUrl: this.path
		// 	}
		// },
		methods: {
			/**
			 * 保存图片
			 */
			getinfo() {
				this.$post('center/fangkeqrcode', {
					id: this.id
				}).then(res => {
					this.path = res.data.path
					this.info = res.data
				})
			},
			saveImage(src) {
				let that = this;
				// 向用户发起授权请求
				uni.authorize({
					scope: 'scope.writePhotosAlbum',
					success: () => {
						// 已授权
						that.downLoadImg(src);
					},
					fail: () => {
						// 拒绝授权，获取当前设置
						uni.getSetting({
							success: (result) => {
								if (!result.authSetting['scope.writePhotosAlbum']) {
									that.isAuth()
								}
							}
						});
					}
				})
			},
			/**
			 * 下载资源，保存图片到系统相册
			 */
			downLoadImg(src) {
				uni.showLoading({
					title: '加载中'
				});
				uni.downloadFile({
					url: src,
					success: (res) => {
						uni.hideLoading();
						if (res.statusCode === 200) {
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success: function() {
									uni.showToast({
										title: "保存成功",
										icon: "none"
									});
								},
								fail: function() {
									uni.showToast({
										title: "保存失败，请稍后重试",
										icon: "none"
									});
								}
							});
						}
					},
					fail: (err) => {
						uni.showToast({
							title: "失败啦",
							icon: "none"
						});
					}
				})
			},
			/*
			 * 引导用户开启权限
			 */
			isAuth() {
				uni.showModal({
					content: '由于您还没有允许保存图片到您相册里,无法进行保存,请点击确定允许授权',
					success: (res) => {
						if (res.confirm) {
							uni.openSetting({
								success: (result) => {
									console.log(result.authSetting);
								}
							});
						}
					}
				});
			},

			getqrcode() {
				this.$post('center/getroomqrcode', {
					roomId: this.roomId,
					shenfen: this.shenfen
				}).then(res => {
					if (res.code === 0) {
						this.name = res.data.user.name;
						this.headimgurl = res.data.user.headimgurl;
						this.code = res.data.code;
						this.endtime = res.data.endtime;
						this.path = res.data.path;
					}
				})
			},
			fanhui() {
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style>
	.beijing {
		width: 100vw;
		height: 100vh;
		z-index: -3;
		position: absolute;
		top: 0;
	}

	.beijing1 {
		width: 550rpx;
		height: 1078rpx;
		z-index: -2;
		position: absolute;
		top: 223rpx;
		left: 100rpx;
	}

	.beijing2 {
		margin: 80rpx 35rpx;
		width: 420rpx;
		height: 420rpx;
	}

	.top {
		z-index: 5;
		width: 700rpx;
		margin: 0 auto;
		display: flex;
		justify-content: space-between;
		align-items: flex-end;
	}

	.toptext {
		z-index: 5;
		font-size: 36rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 36rpx;
	}

	.text {
		margin-top: -70rpx;
		width: 500rpx;
		font-size: 18rpx;
		text-align: center;
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		color: #999999;
		line-height: 44rpx;
	}

	.top1img {
		z-index: 5;
		width: 20rpx;
		height: 36rpx;
	}

	.box {
		width: 500rpx;
		margin: 0 auto;
		margin-top: 20rpx;
	}

	.box1 {
		display: flex;
		height: 200rpx;
	}

	.box1img {
		width: 94rpx;
		height: 94rpx;
	}

	.box2 {
		margin-left: 20rpx;
	}

	.box2text {
		font-size: 24rpx;
		font-family: Alibaba PuHuiTi;
		font-weight: 500;
		color: #333333;
		line-height: 44rpx;
	}

	.box22text1 {
		font-size: 16rpx;
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		color: #999999;
		line-height: 44rpx;
	}

	.box-2 {
		margin: 30rpx 0;
		display: flex;
		justify-content: space-between;
	}

	.box2-1 {
		font-size: 20rpx;
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		color: #999999;
		line-height: 44rpx;
	}

	.box2-2 {
		display: flex;
		align-items: center;
	}

	.box2-2text {
		font-size: 26rpx;
		font-family: Alibaba PuHuiTi;
		font-weight: bold;
		color: #FB6F25;
		line-height: 44rpx;
	}

	.box2-2textx {
		font-size: 20rpx;
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		color: #333333;
		line-height: 44rpx;
	}

	.box2-2img {
		margin-left: 10rpx;
		width: 16rpx;
		height: 16rpx;
	}

	.end {
		width: 300rpx;
		margin: 20rpx auto;
		display: flex;
		justify-content: space-around;

	}

	.end1 {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.end1img {
		width: 61rpx;
		height: 61rpx;
	}

	.end1text {
		font-size: 18rpx;
		font-family: Alibaba PuHuiTi;
		font-weight: 500;
		color: #333333;
		line-height: 44rpx;
	}
</style>
